/*
 * Copyright (C) 2009 Google Inc.  All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.zinnaworks.smart_cloud_gamepad.util;

import android.util.Log;

import com.google.anymote.Key;
import com.google.anymote.Key.Code;
import com.zinnaworks.smart_cloud_gamepad.protocol.ICommandSender;

/**
 * Lists common control actions on a Google TV box.
 *
 */
public enum Action {

	BACKSPACE {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_DEL);
		}
	},

	SPACE {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_SPACE);
		}
	},

	CLICK_DOWN {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.BTN_MOUSE, Key.Action.DOWN);
		}
	},

	CLICK_UP {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.BTN_MOUSE, Key.Action.UP);
		}
	},

	DPAD_CENTER {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_DPAD_CENTER);
		}
	},

	DPAD_DOWN {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_DPAD_DOWN);
		}
	},

	DPAD_DOWN_PRESSED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_DPAD_DOWN, Key.Action.DOWN);
		}
	},

	DPAD_DOWN_RELEASED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_DPAD_DOWN, Key.Action.UP);
		}
	},

	DPAD_LEFT {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_DPAD_LEFT);
		}
	},

	DPAD_LEFT_PRESSED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_DPAD_LEFT, Key.Action.DOWN);
		}
	},

	DPAD_LEFT_RELEASED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_DPAD_LEFT, Key.Action.UP);
		}
	},

	DPAD_RIGHT {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_DPAD_RIGHT);
		}
	},

	DPAD_RIGHT_PRESSED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_DPAD_RIGHT, Key.Action.DOWN);
		}
	},

	DPAD_RIGHT_RELEASED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_DPAD_RIGHT, Key.Action.UP);
		}
	},

	DPAD_UP {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_DPAD_UP);
		}
	},

	DPAD_UP_PRESSED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_DPAD_UP, Key.Action.DOWN);
		}
	},

	DPAD_UP_RELEASED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_DPAD_UP, Key.Action.UP);
		}
	},

	ENTER {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_ENTER);
		}
	},

	ESCAPE {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_ESCAPE);
		}
	},

	GO_TO_DVR {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_DVR);
		}
	},

	GO_TO_GUIDE {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_GUIDE);
		}
	},

	GO_TO_LIVE_TV {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_LIVE);
		}
	},

	NAVBAR {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_SEARCH);
		}
	},

	POWER {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_POWER);
		}
	},

	VOLUME_DOWN {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_VOLUME_DOWN);
		}
	},

	VOLUME_UP {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_VOLUME_UP);
		}
	},

	ZOOM_IN {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_ZOOM_IN);
		}
	},

	ZOOM_OUT {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_ZOOM_OUT);
		}
	},

	COLOR_RED {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_PROG_RED);
		}
	},

	COLOR_GREEN {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_PROG_GREEN);
		}
	},

	COLOR_YELLOW {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_PROG_YELLOW);
		}
	},

	COLOR_BLUE {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_PROG_BLUE);
		}
	},

	POWER_BD {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_BD_POWER);
		}
	},

	INPUT_BD {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_BD_INPUT);
		}
	},

	POWER_AVR {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_AVR_POWER);
		}
	},

	INPUT_AVR {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_AVR_INPUT);
		}
	},

	POWER_TV {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_TV_POWER);
		}
	},

	INPUT_TV {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_TV_INPUT);
		}
	},

	BD_TOP_MENU {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_BD_TOP_MENU);
		}
	},

	BD_MENU {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_BD_POPUP_MENU);
		}
	},

	EJECT {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_EJECT);
		}
	},

	AUDIO {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_AUDIO);
		}
	},

	SETTINGS {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_SETTINGS);
		}
	},

	CAPTIONS {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_INSERT);
		}
	},

	KEYCODE_BUTTON_A {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_PAGE_UP);
		}
	},
	KEYCODE_BUTTON_A_PRESSED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_PAGE_UP, Key.Action.DOWN);
		}
	},
	KEYCODE_BUTTON_A_RELEASED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_PAGE_UP, Key.Action.UP);
		}
	},
	KEYCODE_BUTTON_B {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_PAGE_DOWN);
		}
	},
	KEYCODE_BUTTON_B_PRESSED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_PAGE_DOWN, Key.Action.DOWN);
		}
	},
	KEYCODE_BUTTON_B_RELEASED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_PAGE_DOWN, Key.Action.UP);
		}
	},
	KEYCODE_BUTTON_X {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_INFO);
		}
	},
	KEYCODE_BUTTON_X_PRESSED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_INFO, Key.Action.DOWN);
		}
	},
	KEYCODE_BUTTON_X_RELEASED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_INFO, Key.Action.UP);
		}
	},
	KEYCODE_BUTTON_Y {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_WINDOW);
		}
	},
	KEYCODE_BUTTON_Y_PRESSED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_WINDOW, Key.Action.DOWN);
		}
	},
	KEYCODE_BUTTON_Y_RELEASED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_WINDOW, Key.Action.UP);
		}
	},
	KEYCODE_BUTTON_L1 {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_CAPS_LOCK);
		}
	},
	KEYCODE_BUTTON_L1_PRESSED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_CAPS_LOCK, Key.Action.DOWN);
		}
	},
	KEYCODE_BUTTON_L1_RELEASED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_CAPS_LOCK, Key.Action.UP);
		}
	},
	KEYCODE_BUTTON_R1 {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_ESCAPE);
		}
	},
	KEYCODE_BUTTON_R1_PRESSED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_ESCAPE, Key.Action.DOWN);
		}
	},
	KEYCODE_BUTTON_R1_RELEASED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_ESCAPE, Key.Action.UP);
		}
	},
	SELECT {
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.KEYCODE_BACK);
		}
	},
	SELECT_PRESSED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_BACK, Key.Action.DOWN);
		}
	},
	SELECT_RELEASED {
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.KEYCODE_BACK, Key.Action.UP);
		}
	},
	BTN_1
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.BTN_1);
		}
	},
	BTN_1_PRESSED
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.BTN_1, Key.Action.DOWN);
		}
	},
	BTN_1_RELEASED
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.BTN_1, Key.Action.UP);
		}
	},

	BTN_2
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.BTN_2);
		}
	},
	BTN_2_PRESSED
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.BTN_2, Key.Action.DOWN);
		}
	},
	BTN_2_RELEASED
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.BTN_2, Key.Action.UP);
		}
	},
	BTN_3
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.BTN_3);
		}
	},
	BTN_3_PRESSED
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.BTN_3, Key.Action.DOWN);
		}
	},
	BTN_3_RELEASED
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.BTN_3, Key.Action.UP);
		}
	},
	BTN_4
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.BTN_4);
		}
	},
	BTN_4_PRESSED
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.BTN_4, Key.Action.DOWN);
		}
	},
	BTN_4_RELEASED
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.BTN_4, Key.Action.UP);
		}
	},
	BTN_5
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.BTN_5);
		}
	},
	BTN_5_PRESSED
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.BTN_5, Key.Action.DOWN);
		}
	},
	BTN_5_RELEASED
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.BTN_5, Key.Action.UP);
		}
	},
	BTN_6
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.BTN_6);
		}
	},
	BTN_6_PRESSED
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.BTN_6, Key.Action.DOWN);
		}
	},
	BTN_6_RELEASED
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.BTN_6, Key.Action.UP);
		}
	},
	BTN_7
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.BTN_7);
		}
	},
	BTN_7_PRESSED
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.BTN_7, Key.Action.DOWN);
		}
	},
	BTN_7_RELEASED
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.BTN_7, Key.Action.UP);
		}
	},
	BTN_8
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.BTN_8);
		}
	},
	BTN_8_PRESSED
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.BTN_8, Key.Action.DOWN);
		}
	},
	BTN_8_RELEASED
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.BTN_8, Key.Action.UP);
		}
	},
	BTN_9
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.keyPress(Code.BTN_9);
		}
	},
	BTN_9_PRESSED
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.BTN_9, Key.Action.DOWN);
		}
	},
	BTN_9_RELEASED
	{
		@Override
		public void execute(ICommandSender sender) {
			sender.key(Code.BTN_9, Key.Action.UP);
		}
	};








	/**
	 * Executes the action.
	 *
	 * @param sender  interface to the remote box
	 */
	public abstract void execute(ICommandSender sender);
}
